Skip to content

New Test for IQueryPlanning and filtering with string collection#4202

Closed
a-shtifanov-laya wants to merge 1 commit intoJasperFx:masterfrom
a-shtifanov-laya:master
Closed

New Test for IQueryPlanning and filtering with string collection#4202
a-shtifanov-laya wants to merge 1 commit intoJasperFx:masterfrom
a-shtifanov-laya:master

Conversation

@a-shtifanov-laya
Copy link
Copy Markdown
Contributor

No description provided.


public class IssuesByTitles: ICompiledListQuery<Issue>, IQueryPlanning
{
[Marten.Events.CodeGeneration.MartenIgnore]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure if this should be used or not. without this attribute it throws an exception because it tries to use undrying type (string) as document type

System.ArgumentOutOfRangeException: This type cannot be used as a Marten document (Parameter 'documentType')
at Marten.Schema.DocumentMapping..ctor(Type documentType, StoreOptions storeOptions) in //src/Marten/Schema/DocumentMapping.cs:line 116
at Marten.Schema.DocumentMapping`1..ctor(StoreOptions storeOptions) in //src/Marten/Schema/DocumentMapping.cs:line 843
....

void IQueryPlanning.SetUniqueValuesForQueryPlanning()
{
Status = "status";
Titles = ["title"];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that the issue is in code generation when IQueryPlanning is used. It produces valid sql and parameters, but it does not use the value from the _query for this array param. Maybe due to MartenIgnore.

public override void ConfigureCommand(Weasel.Postgresql.ICommandBuilder builder, Marten.Internal.IMartenSession session)
{
	var parameters1 = builder.AppendWithParameters(@"select d.data from public.mt_doc_issue as d where (d.data ->> 'Status' = ^ and d.data ->> 'Title' = ANY(^));", '^');

	parameters1[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text;
	parameters1[0].Value = _query.Status;
	parameters1[1].Value = new string[]{"title"}; // <---- here is the constant instead of _query.Titles
	parameters1[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Array | NpgsqlTypes.NpgsqlDbType.Varchar;
}

if i edit it manually to _query.Titles it returns valid results

@a-shtifanov-laya a-shtifanov-laya marked this pull request as ready for review March 26, 2026 12:58
@jeremydmiller
Copy link
Copy Markdown
Member

@a-shtifanov-laya I'm starting to look at this now

jeremydmiller added a commit that referenced this pull request Mar 29, 2026
…anning

Array-typed properties (string[], Guid[], int[], etc.) on compiled query
classes were incorrectly classified as Include members because string[]
implements IList<string>. This caused IsOneOf() parameters to be
hardcoded with template values instead of reading from the query instance.

The fix has four parts:
1. CompiledQueryPlan.sortMembers: check for array types with known
   element-type finders BEFORE the IList<> check
2. ArrayParameterFinder<T>: new finder that matches T[] types and
   provides unique array values for query planning
3. QueryMember.tryToFind: use structural array comparison instead of
   reference equality when matching parameter values
4. ParameterUsage.generateSimpleCode: emit correct composite
   NpgsqlDbType (Array | ElementType) for array parameters

Closes #4202

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants